
<!DOCTYPE HTML>
<html lang="zh-hans" >
    <head>
        <meta charset="UTF-8">
        <meta content="text/html; charset=utf-8" http-equiv="Content-Type">
        <title>openglES示例 · Aivin开发笔记</title>
        <meta http-equiv="X-UA-Compatible" content="IE=edge" />
        <meta name="description" content="">
        <meta name="generator" content="GitBook 3.2.3">
        <meta name="author" content="Aivin">
        
        
    
    <link rel="stylesheet" href="../../gitbook/style.css">

    
            
                
                <link rel="stylesheet" href="../../gitbook/gitbook-plugin-search-plus/search.css">
                
            
                
                <link rel="stylesheet" href="../../gitbook/gitbook-plugin-anchor-navigation-ex/style/plugin.css">
                
            
                
                <link rel="stylesheet" href="../../gitbook/gitbook-plugin-versions-select/plugin.css">
                
            
                
                <link rel="stylesheet" href="../../gitbook/gitbook-plugin-fontsettings/website.css">
                
            
                
                <link rel="stylesheet" href="../../gitbook/gitbook-plugin-tbfed-pagefooter/footer.css">
                
            
                
                <link rel="stylesheet" href="../../gitbook/gitbook-plugin-donate/plugin.css">
                
            
                
                <link rel="stylesheet" href="../../gitbook/gitbook-plugin-local-video/video-js.min.css">
                
            
                
                <link rel="stylesheet" href="../../gitbook/gitbook-plugin-splitter/splitter.css">
                
            
                
                <link rel="stylesheet" href="../../gitbook/gitbook-plugin-expandable-chapters/expandable-chapters.css">
                
            
                
                <link rel="stylesheet" href="../../gitbook/gitbook-plugin-highlight/website.css">
                
            
                
                <link rel="stylesheet" href="../../gitbook/gitbook-plugin-theme-comscore/test.css">
                
            
        

    

    
        
        <link rel="stylesheet" href="../../styles/website.css">
        
    

        
    
    
    
    <meta name="HandheldFriendly" content="true"/>
    <meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <link rel="apple-touch-icon-precomposed" sizes="152x152" href="../../gitbook/images/apple-touch-icon-precomposed-152.png">
    <link rel="shortcut icon" href="../../gitbook/images/favicon.ico" type="image/x-icon">

    
    <link rel="next" href="../视频相关/音视频基础.html" />
    
    
    <link rel="prev" href="GLSL基础.html" />
    

    
        <link rel="shortcut icon" href='../../assets/images/favicon.ico' type="image/x-icon">
    
    
        <link rel="bookmark" href='../../assets/images/favicon.ico' type="image/x-icon">
    
    
    

    </head>
    <body>
        
<div class="book">
    <div class="book-summary">
        
            
<div id="book-search-input" role="search">
    <input type="text" placeholder="输入并搜索" />
</div>

            
                <nav role="navigation">
                


<ul class="summary">
    
    

    

    
        
        
    
        <li class="chapter " data-level="1.1" data-path="../../">
            
                <a href="../../">
            
                    
                    项目说明
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2" data-path="../linux/linux基础.html">
            
                <a href="../linux/linux基础.html">
            
                    
                    linux
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.2.1" data-path="../linux/linux基础.html">
            
                <a href="../linux/linux基础.html">
            
                    
                    linux基础
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.2" data-path="../linux/android底层开发.html">
            
                <a href="../linux/android底层开发.html">
            
                    
                    android底层开发
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.3" data-path="../c语言/c基础.html">
            
                <a href="../c语言/c基础.html">
            
                    
                    c
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.3.1" data-path="../c语言/c基础.html">
            
                <a href="../c语言/c基础.html">
            
                    
                    c基础
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.4" data-path="../c++/c++基础.html">
            
                <a href="../c++/c++基础.html">
            
                    
                    c++
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.4.1" data-path="../c++/c++基础.html">
            
                <a href="../c++/c++基础.html">
            
                    
                    c++基础
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.5" data-path="../QT/QT基础.html">
            
                <a href="../QT/QT基础.html">
            
                    
                    QT
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.5.1" data-path="../QT/QT基础.html">
            
                <a href="../QT/QT基础.html">
            
                    
                    QT基础
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.6" data-path="../jni/JNI基础.html">
            
                <a href="../jni/JNI基础.html">
            
                    
                    JNI
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.6.1" data-path="../jni/JNI基础.html">
            
                <a href="../jni/JNI基础.html">
            
                    
                    JNI基础
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.6.2" data-path="../jni/JNI例子.html">
            
                <a href="../jni/JNI例子.html">
            
                    
                    JNI例子
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.7" data-path="../SDL/SDL基础.html">
            
                <a href="../SDL/SDL基础.html">
            
                    
                    SDL
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.7.1" data-path="../SDL/SDL基础.html">
            
                <a href="../SDL/SDL基础.html">
            
                    
                    SDL基础
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.8" data-path="../ffmpeg/ffmpeg基础.html">
            
                <a href="../ffmpeg/ffmpeg基础.html">
            
                    
                    ffmpeg
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.8.1" data-path="../ffmpeg/ffmpeg基础.html">
            
                <a href="../ffmpeg/ffmpeg基础.html">
            
                    
                    ffmpeg基础
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.8.2" data-path="../ffmpeg/ffmpeg示例代码.html">
            
                <a href="../ffmpeg/ffmpeg示例代码.html">
            
                    
                    ffmpeg示例代码
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.8.3" data-path="../ffmpeg/ffmpeg软解rtsp简单直播.html">
            
                <a href="../ffmpeg/ffmpeg软解rtsp简单直播.html">
            
                    
                    ffmpeg软解rtsp简单直播
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.8.4" data-path="../ffmpeg/rtsp服务器.html">
            
                <a href="../ffmpeg/rtsp服务器.html">
            
                    
                    rtsp服务器Windows
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.9" data-path="../opencv/opencv模块.html">
            
                <a href="../opencv/opencv模块.html">
            
                    
                    opencv模块
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.9.1" data-path="../opencv/opencv.html">
            
                <a href="../opencv/opencv.html">
            
                    
                    opencv
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.10" data-path="../openSLES/openSLES基础.html">
            
                <a href="../openSLES/openSLES基础.html">
            
                    
                    openSLES
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.10.1" data-path="../openSLES/openSLES基础.html">
            
                <a href="../openSLES/openSLES基础.html">
            
                    
                    openSLES基础
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.11" data-path="../SoundTouch/移植SoundTouch.html">
            
                <a href="../SoundTouch/移植SoundTouch.html">
            
                    
                    SoundTouch
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.11.1" data-path="../SoundTouch/移植SoundTouch.html">
            
                <a href="../SoundTouch/移植SoundTouch.html">
            
                    
                    移植SoundTouch
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.11.2" data-path="../SoundTouch/实现音频变速和变调.html">
            
                <a href="../SoundTouch/实现音频变速和变调.html">
            
                    
                    实现音频变速和变调
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.12" data-path="openGLES基础.html">
            
                <a href="openGLES基础.html">
            
                    
                    openGLES模块
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.12.1" data-path="openGLES基础.html">
            
                <a href="openGLES基础.html">
            
                    
                    openGLES基础
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.12.2" data-path="GLSL基础.html">
            
                <a href="GLSL基础.html">
            
                    
                    GLSL基础
            
                </a>
            

            
        </li>
    
        <li class="chapter active" data-level="1.12.3" data-path="openglES示例.html">
            
                <a href="openglES示例.html">
            
                    
                    openglES示例
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.13" data-path="../视频相关/音视频基础.html">
            
                <a href="../视频相关/音视频基础.html">
            
                    
                    音视频术语-文件格式-协议
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.13.1" data-path="../视频相关/音视频基础.html">
            
                <a href="../视频相关/音视频基础.html">
            
                    
                    音视频基础
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.13.2" data-path="../视频相关/RTSP.html">
            
                <a href="../视频相关/RTSP.html">
            
                    
                    RTSP
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.13.3" data-path="../视频相关/RTP.html">
            
                <a href="../视频相关/RTP.html">
            
                    
                    RTP
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.13.4" data-path="../视频相关/RTCP.html">
            
                <a href="../视频相关/RTCP.html">
            
                    
                    RTCP
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.13.5" data-path="../视频相关/H264.html">
            
                <a href="../视频相关/H264.html">
            
                    
                    H264
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.13.6" data-path="../视频相关/YUV.html">
            
                <a href="../视频相关/YUV.html">
            
                    
                    YUV
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.13.7" data-path="../视频相关/SurfaceView.html">
            
                <a href="../视频相关/SurfaceView.html">
            
                    
                    SurfaceView
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.13.8" data-path="../视频相关/RTMP.html">
            
                <a href="../视频相关/RTMP.html">
            
                    
                    RTMP
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.13.9" data-path="../视频相关/AAC详解.html">
            
                <a href="../视频相关/AAC详解.html">
            
                    
                    AAC详解
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.14" data-path="../音视频相关代码/音视频相关代码.html">
            
                <a href="../音视频相关代码/音视频相关代码.html">
            
                    
                    音视频相关代码
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.15" data-path="../ndk/NDK编译基础.html">
            
                <a href="../ndk/NDK编译基础.html">
            
                    
                    NDK工程编译
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.15.1" data-path="../ndk/NDK编译基础.html">
            
                <a href="../ndk/NDK编译基础.html">
            
                    
                    NDK编译基础
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.15.2" data-path="../ndk/cmake方式.html">
            
                <a href="../ndk/cmake方式.html">
            
                    
                    cmake
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.15.3" data-path="../ndk/Android.mk模板.html">
            
                <a href="../ndk/Android.mk模板.html">
            
                    
                    Android.mk
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.15.4" data-path="../ndk/Application.mk模板.html">
            
                <a href="../ndk/Application.mk模板.html">
            
                    
                    Application.mk
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    

    

    <li class="divider"></li>

    <li>
        <a href="https://www.gitbook.com" target="blank" class="gitbook-link">
            本书使用 GitBook 发布
        </a>
    </li>
</ul>


                </nav>
            
        
    </div>

    <div class="book-body">
        
            <div class="body-inner">
                
                    

<div class="book-header" role="navigation">
    

    <!-- Title -->
    <h1>
        <i class="fa fa-circle-o-notch fa-spin"></i>
        <a href="../.." >openglES示例</a>
    </h1>
</div>




                    <div class="page-wrapper" tabindex="-1" role="main">
                        <div class="page-inner">
                            
<div class="search-plus" id="book-search-results">
    <div class="search-noresults">
    
                                <section class="normal markdown-section">
                                
                                <div id="anchor-navigation-ex-navbar"><i class="fa fa-navicon"></i><ul><li><span class="title-icon "></span><a href="#opengles&#x793A;&#x4F8B;"><b>1. </b>openglES&#x793A;&#x4F8B;</a></li><ul><li><span class="title-icon "></span><a href="#&#x5168;&#x666F;"><b>1.1. </b>&#x5168;&#x666F;</a></li><ul><li><span class="title-icon "></span><a href="#&#x5168;&#x666F;&#x89C6;&#x9891;&#x7684;&#x539F;&#x7406;"><b>1.1.1. </b>&#x5168;&#x666F;&#x89C6;&#x9891;&#x7684;&#x539F;&#x7406;</a></li></ul><li><span class="title-icon "></span><a href="#&#x5F69;&#x8272;&#x4E09;&#x89D2;&#x5F62;"><b>1.2. </b>&#x5F69;&#x8272;&#x4E09;&#x89D2;&#x5F62;</a></li><li><span class="title-icon "></span><a href="#&#x6B63;&#x65B9;&#x5F62;"><b>1.3. </b>&#x6B63;&#x65B9;&#x5F62;</a></li><li><span class="title-icon "></span><a href="#&#x5706;"><b>1.4. </b>&#x5706;</a></li></ul></ul></div><a href="#opengles&#x793A;&#x4F8B;" id="anchorNavigationExGoTop"><i class="fa fa-arrow-up"></i></a><h1 id="opengles&#x793A;&#x4F8B;"><a name="opengles&#x793A;&#x4F8B;" class="anchor-navigation-ex-anchor" href="#opengles&#x793A;&#x4F8B;"><i class="fa fa-link" aria-hidden="true"></i></a>1. openglES&#x793A;&#x4F8B;</h1>
<h2 id="&#x5168;&#x666F;"><a name="&#x5168;&#x666F;" class="anchor-navigation-ex-anchor" href="#&#x5168;&#x666F;"><i class="fa fa-link" aria-hidden="true"></i></a>1.1. &#x5168;&#x666F;</h2>
<table>
<thead>
<tr>
<th>&#x5168;&#x666F;&#x89C6;&#x9891;&#x7C7B;&#x578B;</th>
<th>&#x7279;&#x70B9;</th>
</tr>
</thead>
<tbody>
<tr>
<td>Sphere</td>
<td></td>
</tr>
<tr>
<td>Skybox</td>
<td></td>
</tr>
<tr>
<td>Cubemap</td>
<td></td>
</tr>
<tr>
<td>Cylinder</td>
<td></td>
</tr>
</tbody>
</table>
<h3 id="&#x5168;&#x666F;&#x89C6;&#x9891;&#x7684;&#x539F;&#x7406;"><a name="&#x5168;&#x666F;&#x89C6;&#x9891;&#x7684;&#x539F;&#x7406;" class="anchor-navigation-ex-anchor" href="#&#x5168;&#x666F;&#x89C6;&#x9891;&#x7684;&#x539F;&#x7406;"><i class="fa fa-link" aria-hidden="true"></i></a>1.1.1. &#x5168;&#x666F;&#x89C6;&#x9891;&#x7684;&#x539F;&#x7406;</h3>
<h2 id="&#x5F69;&#x8272;&#x4E09;&#x89D2;&#x5F62;"><a name="&#x5F69;&#x8272;&#x4E09;&#x89D2;&#x5F62;" class="anchor-navigation-ex-anchor" href="#&#x5F69;&#x8272;&#x4E09;&#x89D2;&#x5F62;"><i class="fa fa-link" aria-hidden="true"></i></a>1.2. &#x5F69;&#x8272;&#x4E09;&#x89D2;&#x5F62;</h2>
<pre><code class="lang-java"><span class="hljs-keyword">public</span> <span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">MyRenderer</span> <span class="hljs-keyword">implements</span> <span class="hljs-title">GLSurfaceView</span>.<span class="hljs-title">Renderer</span> </span>{
    <span class="hljs-keyword">private</span> Context context ;
    <span class="hljs-keyword">private</span> <span class="hljs-keyword">float</span>[] mViewMatrix=<span class="hljs-keyword">new</span> <span class="hljs-keyword">float</span>[<span class="hljs-number">16</span>];
    <span class="hljs-keyword">private</span> <span class="hljs-keyword">float</span>[] mProjectMatrix=<span class="hljs-keyword">new</span> <span class="hljs-keyword">float</span>[<span class="hljs-number">16</span>];
    <span class="hljs-keyword">private</span> <span class="hljs-keyword">float</span>[] mMVPMatrix=<span class="hljs-keyword">new</span> <span class="hljs-keyword">float</span>[<span class="hljs-number">16</span>];
    <span class="hljs-keyword">private</span> <span class="hljs-keyword">int</span> mProgram;
    <span class="hljs-keyword">private</span> FloatBuffer vertexBuffer;
    <span class="hljs-keyword">private</span> FloatBuffer colorBuffer;

    <span class="hljs-comment">/**&#x9876;&#x70B9;&#x5750;&#x6807;*/</span>
    <span class="hljs-keyword">private</span> <span class="hljs-keyword">float</span> triangleCoords[] = {
   <span class="hljs-number">0.5f</span>,  <span class="hljs-number">0.5f</span>, <span class="hljs-number">0.0f</span>,
   -<span class="hljs-number">0.5f</span>, -<span class="hljs-number">0.5f</span>, <span class="hljs-number">0.0f</span>,
   <span class="hljs-number">0.5f</span>, -<span class="hljs-number">0.5f</span>, <span class="hljs-number">0.0f</span>
    };

    <span class="hljs-keyword">float</span> color[] = {
   <span class="hljs-number">0.0f</span>, <span class="hljs-number">1.0f</span>, <span class="hljs-number">0.0f</span>, <span class="hljs-number">1.0f</span> ,
   <span class="hljs-number">1.0f</span>, <span class="hljs-number">0.0f</span>, <span class="hljs-number">0.0f</span>, <span class="hljs-number">1.0f</span>,
   <span class="hljs-number">0.0f</span>, <span class="hljs-number">0.0f</span>, <span class="hljs-number">1.0f</span>, <span class="hljs-number">1.0f</span>
    };

    <span class="hljs-function"><span class="hljs-keyword">public</span> <span class="hljs-title">MyRenderer</span><span class="hljs-params">( Context context)</span></span>{
        <span class="hljs-keyword">this</span>.context = context;
        init();
    }

    <span class="hljs-function"><span class="hljs-keyword">private</span> <span class="hljs-keyword">void</span> <span class="hljs-title">init</span><span class="hljs-params">()</span>  </span>{
        ByteBuffer bb = ByteBuffer.allocateDirect(  triangleCoords.length * <span class="hljs-number">4</span>);
        bb.order(ByteOrder.nativeOrder());
        vertexBuffer = bb.asFloatBuffer();
        vertexBuffer.put(triangleCoords);
        vertexBuffer.position(<span class="hljs-number">0</span>);

        ByteBuffer dd = ByteBuffer.allocateDirect(  color.length * <span class="hljs-number">4</span>);
        dd.order(ByteOrder.nativeOrder());
        colorBuffer = dd.asFloatBuffer();
        colorBuffer.put(color);
        colorBuffer.position(<span class="hljs-number">0</span>);
    }

    <span class="hljs-meta">@Override</span>
    <span class="hljs-function"><span class="hljs-keyword">public</span> <span class="hljs-keyword">void</span> <span class="hljs-title">onSurfaceCreated</span><span class="hljs-params">(GL10 gl, EGLConfig config)</span> </span>{
        String vertexShaderCode = MyAssetsTool.loadFromAssetsFile(<span class="hljs-string">&quot;vertex.sh&quot;</span> ,context);
        String fragmentShaderCode = MyAssetsTool.loadFromAssetsFile(<span class="hljs-string">&quot;fragment.sh&quot;</span> ,context);
        <span class="hljs-keyword">int</span> vertexShader = loadShader(GLES20.GL_VERTEX_SHADER,  vertexShaderCode);
        <span class="hljs-keyword">int</span> fragmentShader = loadShader(GLES20.GL_FRAGMENT_SHADER,  fragmentShaderCode);

        mProgram = GLES20.glCreateProgram();
        GLES20.glAttachShader(mProgram, vertexShader);
        GLES20.glAttachShader(mProgram, fragmentShader);
        GLES20.glLinkProgram(mProgram);
    }

    <span class="hljs-meta">@Override</span>
    <span class="hljs-function"><span class="hljs-keyword">public</span> <span class="hljs-keyword">void</span> <span class="hljs-title">onSurfaceChanged</span><span class="hljs-params">(GL10 gl, <span class="hljs-keyword">int</span> width, <span class="hljs-keyword">int</span> height)</span> </span>{
        <span class="hljs-comment">//&#x8BA1;&#x7B97;&#x5BBD;&#x9AD8;&#x6BD4;</span>
        <span class="hljs-keyword">float</span> ratio=(<span class="hljs-keyword">float</span>)width/height;
        Matrix.frustumM(mProjectMatrix, <span class="hljs-number">0</span>, -ratio, ratio, -<span class="hljs-number">1</span>, <span class="hljs-number">1</span>, <span class="hljs-number">3</span>, <span class="hljs-number">7</span>);
        Matrix.setLookAtM(mViewMatrix, <span class="hljs-number">0</span>, <span class="hljs-number">0</span>, <span class="hljs-number">0</span>, <span class="hljs-number">7.0f</span>, <span class="hljs-number">0f</span>, <span class="hljs-number">0f</span>, <span class="hljs-number">0f</span>, <span class="hljs-number">0f</span>, <span class="hljs-number">1.0f</span>, <span class="hljs-number">0.0f</span>);
        Matrix.multiplyMM(mMVPMatrix,<span class="hljs-number">0</span>,mProjectMatrix,<span class="hljs-number">0</span>,mViewMatrix,<span class="hljs-number">0</span>);
    }

    <span class="hljs-meta">@Override</span>
    <span class="hljs-function"><span class="hljs-keyword">public</span> <span class="hljs-keyword">void</span> <span class="hljs-title">onDrawFrame</span><span class="hljs-params">(GL10 gl)</span> </span>{
        GLES20.glClear(GLES20.GL_COLOR_BUFFER_BIT | GLES20.GL_DEPTH_BUFFER_BIT);
        GLES20.glUseProgram(mProgram);

        <span class="hljs-keyword">int</span> mMatrixHandler= GLES20.glGetUniformLocation(mProgram,<span class="hljs-string">&quot;vMatrix&quot;</span>);
        GLES20.glUniformMatrix4fv(mMatrixHandler,<span class="hljs-number">1</span>,<span class="hljs-keyword">false</span>,mMVPMatrix,<span class="hljs-number">0</span>);

        <span class="hljs-comment">// &#x5750;&#x6807;</span>
        <span class="hljs-keyword">int</span> mPositionHandle = GLES20.glGetAttribLocation(mProgram, <span class="hljs-string">&quot;vPosition&quot;</span>);
        GLES20.glEnableVertexAttribArray(mPositionHandle);
        GLES20.glVertexAttribPointer(mPositionHandle, <span class="hljs-number">3</span>,  GLES20.GL_FLOAT, <span class="hljs-keyword">false</span>, <span class="hljs-number">3</span>*<span class="hljs-number">4</span>, vertexBuffer);

        <span class="hljs-comment">// &#x989C;&#x8272;</span>
        <span class="hljs-keyword">int</span> mColorHandle = GLES20.glGetAttribLocation(mProgram, <span class="hljs-string">&quot;aColor&quot;</span>);
        GLES20.glEnableVertexAttribArray(mColorHandle);
        GLES20.glVertexAttribPointer(mColorHandle,<span class="hljs-number">4</span>,  GLES20.GL_FLOAT,<span class="hljs-keyword">false</span>, <span class="hljs-number">0</span>,colorBuffer);

        <span class="hljs-comment">// &#x7ED8;&#x5236;</span>
        GLES20.glDrawArrays(GLES20.GL_TRIANGLES, <span class="hljs-number">0</span>, <span class="hljs-number">3</span>);
        GLES20.glDisableVertexAttribArray(mPositionHandle);

    }

    <span class="hljs-function"><span class="hljs-keyword">private</span> <span class="hljs-keyword">int</span> <span class="hljs-title">loadShader</span><span class="hljs-params">(<span class="hljs-keyword">int</span> type, String shaderCode)</span></span>{
        <span class="hljs-keyword">int</span> shader = GLES20.glCreateShader(type);
        GLES20.glShaderSource(shader, shaderCode);
        GLES20.glCompileShader(shader);
        <span class="hljs-keyword">return</span> shader;
    }

}

<span class="hljs-comment">/**
 * &#x4ECE; assets &#x76EE;&#x5F55;&#x4E2D;&#x52A0;&#x8F7D; &#x6587;&#x4EF6; &#x8F6C;&#x4E3A; String
 * <span class="hljs-doctag">@param</span> fname &#x57FA;&#x4E8E;assets&#x7684;&#x7EDD;&#x5BF9;&#x8DEF;&#x5F84;
 * <span class="hljs-doctag">@param</span> context context
 * <span class="hljs-doctag">@return</span> String
 */</span>
<span class="hljs-function"><span class="hljs-keyword">public</span> <span class="hljs-keyword">static</span> String <span class="hljs-title">loadFromAssetsFile</span><span class="hljs-params">(String fname, Context context)</span></span>{
    StringBuilder result=<span class="hljs-keyword">new</span> StringBuilder();
    <span class="hljs-keyword">try</span>{
        InputStream is=context.getResources().getAssets().open(fname);
        <span class="hljs-keyword">int</span> ch;
        <span class="hljs-keyword">byte</span>[] buffer=<span class="hljs-keyword">new</span> <span class="hljs-keyword">byte</span>[<span class="hljs-number">1024</span>];
        <span class="hljs-keyword">while</span> (-<span class="hljs-number">1</span>!=(ch=is.read(buffer))){
            result.append(<span class="hljs-keyword">new</span> String(buffer,<span class="hljs-number">0</span>,ch));
        }
    }<span class="hljs-keyword">catch</span> (Exception e){
        <span class="hljs-keyword">return</span> <span class="hljs-keyword">null</span>;
    }
    <span class="hljs-keyword">return</span> result.toString().replaceAll(<span class="hljs-string">&quot;\\r\\n&quot;</span>,<span class="hljs-string">&quot;\n&quot;</span>);
}

<span class="hljs-comment">// fragment.sh</span>
precision mediump <span class="hljs-keyword">float</span>;
varying vec4 vColor;
<span class="hljs-function"><span class="hljs-keyword">void</span> <span class="hljs-title">main</span><span class="hljs-params">()</span> </span>{
 gl_FragColor = vColor;
}

<span class="hljs-comment">// vertex.sh</span>
attribute vec4 vPosition;
uniform mat4 vMatrix;
varying  vec4 vColor;
attribute vec4 aColor;
<span class="hljs-function"><span class="hljs-keyword">void</span> <span class="hljs-title">main</span><span class="hljs-params">()</span> </span>{
    gl_Position = vMatrix * vPosition;
    vColor= aColor;
}
</code></pre>
<h2 id="&#x6B63;&#x65B9;&#x5F62;"><a name="&#x6B63;&#x65B9;&#x5F62;" class="anchor-navigation-ex-anchor" href="#&#x6B63;&#x65B9;&#x5F62;"><i class="fa fa-link" aria-hidden="true"></i></a>1.3. &#x6B63;&#x65B9;&#x5F62;</h2>
<p>&#x53EF;&#x4EE5;&#x770B;&#x505A;&#x7531;&#x4E24;&#x4E2A;&#x4E09;&#x89D2;&#x5F62;&#x7EC4;&#x6210;&#x3002;</p>
<pre><code class="lang-java"><span class="hljs-keyword">public</span> <span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">MyRenderer</span> <span class="hljs-keyword">implements</span> <span class="hljs-title">GLSurfaceView</span>.<span class="hljs-title">Renderer</span> </span>{
    <span class="hljs-keyword">private</span> Context context ;
    <span class="hljs-keyword">private</span> <span class="hljs-keyword">float</span>[] mViewMatrix=<span class="hljs-keyword">new</span> <span class="hljs-keyword">float</span>[<span class="hljs-number">16</span>];
    <span class="hljs-keyword">private</span> <span class="hljs-keyword">float</span>[] mProjectMatrix=<span class="hljs-keyword">new</span> <span class="hljs-keyword">float</span>[<span class="hljs-number">16</span>];
    <span class="hljs-keyword">private</span> <span class="hljs-keyword">float</span>[] mMVPMatrix=<span class="hljs-keyword">new</span> <span class="hljs-keyword">float</span>[<span class="hljs-number">16</span>];
    <span class="hljs-keyword">private</span> <span class="hljs-keyword">int</span> mProgram;
    <span class="hljs-comment">/**&#x9876;&#x70B9;&#x5750;&#x6807;&#x6570;&#x636E;*/</span>
    <span class="hljs-keyword">private</span> FloatBuffer vertexBuffer;
    <span class="hljs-comment">/**&#x9876;&#x70B9;&#x7D22;&#x5F15;&#x6570;&#x636E;*/</span>
    <span class="hljs-keyword">private</span> ShortBuffer indexBuffer;
    <span class="hljs-comment">/**&#x9876;&#x70B9;&#x5750;&#x6807;*/</span>
    <span class="hljs-keyword">private</span> <span class="hljs-keyword">float</span> triangleCoords[] = {
            -<span class="hljs-number">0.5f</span>,  <span class="hljs-number">0.5f</span>, <span class="hljs-number">0.0f</span>,
            -<span class="hljs-number">0.5f</span>, -<span class="hljs-number">0.5f</span>, <span class="hljs-number">0.0f</span>,
            <span class="hljs-number">0.5f</span>, -<span class="hljs-number">0.5f</span>, <span class="hljs-number">0.0f</span>,
            <span class="hljs-number">0.5f</span>,  <span class="hljs-number">0.5f</span>, <span class="hljs-number">0.0f</span>
    };
    <span class="hljs-comment">/**&#x7D22;&#x5F15;&#x6CD5;*/</span>
    <span class="hljs-keyword">private</span> <span class="hljs-keyword">short</span> index[]={  <span class="hljs-number">0</span>,<span class="hljs-number">1</span>,<span class="hljs-number">2</span>,<span class="hljs-number">0</span>,<span class="hljs-number">2</span>,<span class="hljs-number">3</span> };

    <span class="hljs-keyword">float</span> color[] = {
       <span class="hljs-number">0.0f</span>, <span class="hljs-number">1.0f</span>, <span class="hljs-number">0.0f</span>, <span class="hljs-number">1.0f</span> ,
       <span class="hljs-number">1.0f</span>, <span class="hljs-number">1.0f</span>, <span class="hljs-number">0.0f</span>, <span class="hljs-number">1.0f</span>,
       <span class="hljs-number">0.0f</span>, <span class="hljs-number">0.0f</span>, <span class="hljs-number">1.0f</span>, <span class="hljs-number">1.0f</span>
    };

    <span class="hljs-function"><span class="hljs-keyword">public</span> <span class="hljs-title">MyRenderer</span><span class="hljs-params">( Context context)</span></span>{
        <span class="hljs-keyword">this</span>.context = context;
        init();
    }
    <span class="hljs-function"><span class="hljs-keyword">private</span> <span class="hljs-keyword">void</span> <span class="hljs-title">init</span><span class="hljs-params">()</span>  </span>{
        ByteBuffer bb = ByteBuffer.allocateDirect(  triangleCoords.length * <span class="hljs-number">4</span>);
        bb.order(ByteOrder.nativeOrder());
        vertexBuffer = bb.asFloatBuffer();
        vertexBuffer.put(triangleCoords);
        vertexBuffer.position(<span class="hljs-number">0</span>);

        ByteBuffer dd = ByteBuffer.allocateDirect(  color.length * <span class="hljs-number">4</span>);
        dd.order(ByteOrder.nativeOrder());
        indexBuffer=dd.asShortBuffer();
        indexBuffer.put(index);
        indexBuffer.position(<span class="hljs-number">0</span>);
    }

    <span class="hljs-meta">@Override</span>
    <span class="hljs-function"><span class="hljs-keyword">public</span> <span class="hljs-keyword">void</span> <span class="hljs-title">onSurfaceCreated</span><span class="hljs-params">(GL10 gl, EGLConfig config)</span> </span>{
        String vertexShaderCode = MyAssetsTool.loadFromAssetsFile(<span class="hljs-string">&quot;vertex.sh&quot;</span> ,context);
        String fragmentShaderCode = MyAssetsTool.loadFromAssetsFile(<span class="hljs-string">&quot;fragment.sh&quot;</span> ,context);
        <span class="hljs-keyword">int</span> vertexShader = loadShader(GLES20.GL_VERTEX_SHADER,  vertexShaderCode);
        <span class="hljs-keyword">int</span> fragmentShader = loadShader(GLES20.GL_FRAGMENT_SHADER,  fragmentShaderCode);
        mProgram = GLES20.glCreateProgram();
        GLES20.glAttachShader(mProgram, vertexShader);
        GLES20.glAttachShader(mProgram, fragmentShader);
        GLES20.glLinkProgram(mProgram);
    }

    <span class="hljs-meta">@Override</span>
    <span class="hljs-function"><span class="hljs-keyword">public</span> <span class="hljs-keyword">void</span> <span class="hljs-title">onSurfaceChanged</span><span class="hljs-params">(GL10 gl, <span class="hljs-keyword">int</span> width, <span class="hljs-keyword">int</span> height)</span> </span>{
        <span class="hljs-comment">//&#x8BA1;&#x7B97;&#x5BBD;&#x9AD8;&#x6BD4;</span>
        <span class="hljs-keyword">float</span> ratio=(<span class="hljs-keyword">float</span>)width/height;
        Matrix.frustumM(mProjectMatrix, <span class="hljs-number">0</span>, -ratio, ratio, -<span class="hljs-number">1</span>, <span class="hljs-number">1</span>, <span class="hljs-number">3</span>, <span class="hljs-number">7</span>);
        Matrix.setLookAtM(mViewMatrix, <span class="hljs-number">0</span>, <span class="hljs-number">0</span>, <span class="hljs-number">0</span>, <span class="hljs-number">7.0f</span>, <span class="hljs-number">0f</span>, <span class="hljs-number">0f</span>, <span class="hljs-number">0f</span>, <span class="hljs-number">0f</span>, <span class="hljs-number">1.0f</span>, <span class="hljs-number">0.0f</span>);
        Matrix.multiplyMM(mMVPMatrix,<span class="hljs-number">0</span>,mProjectMatrix,<span class="hljs-number">0</span>,mViewMatrix,<span class="hljs-number">0</span>);
    }

    <span class="hljs-meta">@Override</span>
    <span class="hljs-function"><span class="hljs-keyword">public</span> <span class="hljs-keyword">void</span> <span class="hljs-title">onDrawFrame</span><span class="hljs-params">(GL10 gl)</span> </span>{
        GLES20.glClear(GLES20.GL_COLOR_BUFFER_BIT | GLES20.GL_DEPTH_BUFFER_BIT);
        GLES20.glUseProgram(mProgram);

        <span class="hljs-keyword">int</span> mMatrixHandler= GLES20.glGetUniformLocation(mProgram,<span class="hljs-string">&quot;vMatrix&quot;</span>);
        GLES20.glUniformMatrix4fv(mMatrixHandler,<span class="hljs-number">1</span>,<span class="hljs-keyword">false</span>,mMVPMatrix,<span class="hljs-number">0</span>);

        <span class="hljs-keyword">int</span> mPositionHandle = GLES20.glGetAttribLocation(mProgram, <span class="hljs-string">&quot;vPosition&quot;</span>);
        GLES20.glEnableVertexAttribArray(mPositionHandle);

        GLES20.glVertexAttribPointer(mPositionHandle, <span class="hljs-number">3</span>, GLES20.GL_FLOAT, <span class="hljs-keyword">false</span>,  <span class="hljs-number">3</span>*<span class="hljs-number">4</span>, vertexBuffer);
        <span class="hljs-keyword">int</span> mColorHandle = GLES20.glGetUniformLocation(mProgram, <span class="hljs-string">&quot;vColor&quot;</span>);
        GLES20.glUniform4fv(mColorHandle, <span class="hljs-number">1</span>, color, <span class="hljs-number">0</span>);

        GLES20.glDrawElements(GLES20.GL_TRIANGLES,index.length, GLES20.GL_UNSIGNED_SHORT,indexBuffer);
        GLES20.glDisableVertexAttribArray(mPositionHandle);

    }

    <span class="hljs-function"><span class="hljs-keyword">private</span> <span class="hljs-keyword">int</span> <span class="hljs-title">loadShader</span><span class="hljs-params">(<span class="hljs-keyword">int</span> type, String shaderCode)</span></span>{
        <span class="hljs-keyword">int</span> shader = GLES20.glCreateShader(type);
        GLES20.glShaderSource(shader, shaderCode);
        GLES20.glCompileShader(shader);
        <span class="hljs-keyword">return</span> shader;
    }

}
</code></pre>
<pre><code class="lang-xml">attribute vec4 vPosition;
uniform mat4 vMatrix;
void main() {
    gl_Position = vMatrix * vPosition;
}
</code></pre>
<pre><code class="lang-xml">precision mediump float;
uniform vec4 vColor;
void main() {
 //&#x7247;&#x5143;&#x989C;&#x8272;
 gl_FragColor = vColor;
}
</code></pre>
<h2 id="&#x5706;"><a name="&#x5706;" class="anchor-navigation-ex-anchor" href="#&#x5706;"><i class="fa fa-link" aria-hidden="true"></i></a>1.4. &#x5706;</h2>
<p>&#x53EF;&#x4EE5;&#x628A;&#x5706;&#x5F62;&#x770B;&#x6210;&#x4E00;&#x4E2A;&#x6B63;&#x591A;&#x8FB9;&#x5F62;&#xFF0C;&#x8FB9;&#x8D8A;&#x591A;&#xFF0C;&#x5706;&#x8D8A;&#x5E73;&#x6ED1;&#x3002;
<img src="https://gitee.com/hnyer/filesOfGitbook/raw/master/files/201804171623_osChina_&#x753B;&#x5706;.png" alt="">  <br>
A&#x70B9;&#x7684;&#x6A2A;&#x5750;&#x6807;&#x4E3A;&#xFF1A;   r x cos &#x3B8;   <br>
A&#x70B9;&#x7684;&#x7EB5;&#x5750;&#x6807;&#x4E3A;&#xFF1A;   r x sin &#x3B8;</p>
<pre><code class="lang-java"><span class="hljs-comment">//&#x8BBE;&#x7F6E;&#x5706;&#x5FC3;&#x5750;&#x6807;</span>
data.add(<span class="hljs-number">0.0f</span>);
data.add(<span class="hljs-number">0.0f</span>);
data.add(<span class="hljs-number">0f</span>);
<span class="hljs-keyword">float</span> angDegSpan=<span class="hljs-number">360f</span>/count;
<span class="hljs-keyword">for</span>(<span class="hljs-keyword">float</span> i=<span class="hljs-number">0</span>;i&lt;<span class="hljs-number">360</span>+angDegSpan;i+=angDegSpan)
{
    data.add((<span class="hljs-keyword">float</span>) (r*Math.sin(i*Math.PI/<span class="hljs-number">180f</span>)));
    data.add((<span class="hljs-keyword">float</span>)(r*Math.cos(i*Math.PI/<span class="hljs-number">180f</span>)));
    data.add(<span class="hljs-number">0f</span>);
}
</code></pre>
<pre><code class="lang-java"><span class="hljs-keyword">public</span> <span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">MyRenderer</span> <span class="hljs-keyword">implements</span> <span class="hljs-title">GLSurfaceView</span>.<span class="hljs-title">Renderer</span> </span>{
    <span class="hljs-keyword">private</span> Context context;
    <span class="hljs-keyword">private</span> FloatBuffer vertexData;
    <span class="hljs-comment">/**&#x5706;&#x7684;&#x534A;&#x5F84;*/</span>
    <span class="hljs-keyword">private</span> <span class="hljs-keyword">float</span> r = <span class="hljs-number">0.5f</span>;
    <span class="hljs-comment">/**&#x5C06;&#x5706;&#x5206;&#x6210;n&#x4EFD;*/</span>
    <span class="hljs-keyword">private</span> <span class="hljs-keyword">int</span> count = <span class="hljs-number">100</span>;
    <span class="hljs-keyword">private</span> <span class="hljs-keyword">int</span> program;
    <span class="hljs-keyword">private</span> <span class="hljs-keyword">int</span> uColorLocation;
    <span class="hljs-keyword">private</span> <span class="hljs-keyword">int</span> aPositionLocation;
    <span class="hljs-keyword">private</span> <span class="hljs-keyword">final</span> <span class="hljs-keyword">float</span>[] projectionMatrix = <span class="hljs-keyword">new</span> <span class="hljs-keyword">float</span>[<span class="hljs-number">16</span>];
    <span class="hljs-keyword">private</span> <span class="hljs-keyword">int</span> uMatrixLocation;

    <span class="hljs-function"><span class="hljs-keyword">public</span> <span class="hljs-title">MyRenderer</span><span class="hljs-params">(Context context)</span></span>{
        <span class="hljs-keyword">this</span>.context = context;
        init();
    }

    <span class="hljs-function"><span class="hljs-keyword">private</span> <span class="hljs-keyword">void</span> <span class="hljs-title">init</span><span class="hljs-params">()</span></span>{
        ArrayList&lt;Float&gt; data=<span class="hljs-keyword">new</span> ArrayList&lt;&gt;();
        <span class="hljs-comment">//&#x8BBE;&#x7F6E;&#x5706;&#x5FC3;&#x5750;&#x6807;</span>
        data.add(<span class="hljs-number">0.0f</span>);
        data.add(<span class="hljs-number">0.0f</span>);
        data.add(<span class="hljs-number">0f</span>);
        <span class="hljs-keyword">float</span> angDegSpan=<span class="hljs-number">360f</span>/count;
        <span class="hljs-keyword">for</span>(<span class="hljs-keyword">float</span> i=<span class="hljs-number">0</span>;i&lt;<span class="hljs-number">360</span>+angDegSpan;i+=angDegSpan){
            data.add((<span class="hljs-keyword">float</span>) (r*Math.sin(i*Math.PI/<span class="hljs-number">180f</span>)));
            data.add((<span class="hljs-keyword">float</span>)(r*Math.cos(i*Math.PI/<span class="hljs-number">180f</span>)));
            data.add(<span class="hljs-number">0f</span>);
        }
        <span class="hljs-keyword">float</span>[] f=<span class="hljs-keyword">new</span> <span class="hljs-keyword">float</span>[data.size()];
        <span class="hljs-keyword">for</span> (<span class="hljs-keyword">int</span> i=<span class="hljs-number">0</span>;i&lt;f.length;i++){
            f[i]=data.get(i);
        }
        ByteBuffer bb = ByteBuffer.allocateDirect(  f.length * <span class="hljs-number">4</span>);
        bb.order(ByteOrder.nativeOrder());
        vertexData = bb.asFloatBuffer();
        vertexData.put(f);
        vertexData.position(<span class="hljs-number">0</span>);
    }

    <span class="hljs-meta">@Override</span>
    <span class="hljs-function"><span class="hljs-keyword">public</span> <span class="hljs-keyword">void</span> <span class="hljs-title">onSurfaceCreated</span><span class="hljs-params">(GL10 gl, EGLConfig config)</span> </span>{
        gl.glClearColor(<span class="hljs-number">1.0f</span>, <span class="hljs-number">1.0f</span>, <span class="hljs-number">1.0f</span>, <span class="hljs-number">1.0f</span>);

        String vertexShaderCode = MyAssetsTool.loadFromAssetsFile(<span class="hljs-string">&quot;vertex.sh&quot;</span> ,context);
        String fragmentShaderCode = MyAssetsTool.loadFromAssetsFile(<span class="hljs-string">&quot;fragment.sh&quot;</span> ,context);
        <span class="hljs-keyword">int</span> vertexShader = loadShader(GLES20.GL_VERTEX_SHADER,  vertexShaderCode);
        <span class="hljs-keyword">int</span> fragmentShader = loadShader(GLES20.GL_FRAGMENT_SHADER,  fragmentShaderCode);
        program = GLES20.glCreateProgram();
        GLES20.glAttachShader(program, vertexShader);
        GLES20.glAttachShader(program, fragmentShader);
        GLES20.glLinkProgram(program);
        GLES20.glUseProgram(program);

        aPositionLocation = GLES20.glGetAttribLocation(program,  <span class="hljs-string">&quot;a_Position&quot;</span>);
        uMatrixLocation = GLES20.glGetUniformLocation(program, <span class="hljs-string">&quot;u_Matrix&quot;</span>);
        GLES20.glVertexAttribPointer(aPositionLocation, <span class="hljs-number">3</span>,GLES20.GL_FLOAT, <span class="hljs-keyword">false</span>, <span class="hljs-number">0</span>, vertexData);
        GLES20.glEnableVertexAttribArray(aPositionLocation);
        uColorLocation = GLES20.glGetUniformLocation(program, <span class="hljs-string">&quot;vColor&quot;</span>);
    }
    <span class="hljs-meta">@Override</span>
    <span class="hljs-function"><span class="hljs-keyword">public</span> <span class="hljs-keyword">void</span> <span class="hljs-title">onSurfaceChanged</span><span class="hljs-params">(GL10 gl, <span class="hljs-keyword">int</span> width, <span class="hljs-keyword">int</span> height)</span> </span>{
        gl.glViewport(<span class="hljs-number">0</span>,<span class="hljs-number">0</span>,width,height);
        <span class="hljs-keyword">final</span> <span class="hljs-keyword">float</span> aspectRatio = width &gt; height ?  (<span class="hljs-keyword">float</span>) width / (<span class="hljs-keyword">float</span>) height : (<span class="hljs-keyword">float</span>) height / (<span class="hljs-keyword">float</span>) width;
        <span class="hljs-keyword">if</span>(width &gt; height){
            Matrix.orthoM(projectionMatrix, <span class="hljs-number">0</span>, -aspectRatio, aspectRatio, -<span class="hljs-number">1f</span>, <span class="hljs-number">1f</span>, -<span class="hljs-number">1f</span>, <span class="hljs-number">1f</span>);
        }<span class="hljs-keyword">else</span>{
            Matrix.orthoM(projectionMatrix, <span class="hljs-number">0</span>, -<span class="hljs-number">1f</span>, <span class="hljs-number">1f</span>, -aspectRatio, aspectRatio, -<span class="hljs-number">1f</span>, <span class="hljs-number">1f</span>);
        }
    }
    <span class="hljs-meta">@Override</span>
    <span class="hljs-function"><span class="hljs-keyword">public</span> <span class="hljs-keyword">void</span> <span class="hljs-title">onDrawFrame</span><span class="hljs-params">(GL10 gl)</span> </span>{
        GLES20.glClearColor(<span class="hljs-number">0</span>,<span class="hljs-number">0</span>,<span class="hljs-number">0</span>,<span class="hljs-number">0</span>);
        GLES20.glUniform4f(uColorLocation, <span class="hljs-number">0.0f</span>, <span class="hljs-number">0.0f</span>, <span class="hljs-number">1.0f</span>, <span class="hljs-number">1.0f</span>);
        GLES20.glUniformMatrix4fv(uMatrixLocation, <span class="hljs-number">1</span>, <span class="hljs-keyword">false</span>, projectionMatrix,<span class="hljs-number">0</span>);
        GLES20.glDrawArrays(GLES20.GL_TRIANGLE_FAN, <span class="hljs-number">0</span>, count +<span class="hljs-number">2</span>);
    }
    <span class="hljs-function"><span class="hljs-keyword">private</span> <span class="hljs-keyword">int</span> <span class="hljs-title">loadShader</span><span class="hljs-params">(<span class="hljs-keyword">int</span> type, String shaderCode)</span></span>{
        <span class="hljs-keyword">int</span> shader = GLES20.glCreateShader(type);
        GLES20.glShaderSource(shader, shaderCode);
        GLES20.glCompileShader(shader);
        <span class="hljs-keyword">return</span> shader;
    }
}
</code></pre>
<pre><code class="lang-xml">precision mediump float;
uniform vec4 vColor;
void main() {
 gl_FragColor = vColor;
}
</code></pre>
<pre><code class="lang-xml">uniform mat4 u_Matrix;
attribute vec4 a_Position;
void main()
{
    gl_Position = u_Matrix * a_Position;
}
</code></pre>
<footer class="page-footer"><span class="copyright">&#x65E0;&#x7248;&#x6743; &#x53EF;&#x4EE5;&#x65E0;&#x9650;&#x5236;&#x4F7F;&#x7528;&#xFF01; all right reserved&#xFF0C;powered by Gitbook</span><span class="footer-modification">&#x8BE5;&#x6587;&#x4EF6;&#x66F4;&#x65B0;&#x65F6;&#x95F4;&#xFF1A;
2020-08-20 14:17:31
</span></footer>
                                
                                </section>
                            
    </div>
    <div class="search-results">
        <div class="has-results">
            
            <h1 class="search-results-title"><span class='search-results-count'></span> results matching "<span class='search-query'></span>"</h1>
            <ul class="search-results-list"></ul>
            
        </div>
        <div class="no-results">
            
            <h1 class="search-results-title">No results matching "<span class='search-query'></span>"</h1>
            
        </div>
    </div>
</div>

                        </div>
                    </div>
                
            </div>

            
                
                <a href="GLSL基础.html" class="navigation navigation-prev " aria-label="Previous page: GLSL基础">
                    <i class="fa fa-angle-left"></i>
                </a>
                
                
                <a href="../视频相关/音视频基础.html" class="navigation navigation-next " aria-label="Next page: 音视频术语-文件格式-协议">
                    <i class="fa fa-angle-right"></i>
                </a>
                
            
        
    </div>

    <script>
        var gitbook = gitbook || [];
        gitbook.push(function() {
            gitbook.page.hasChanged({"page":{"title":"openglES示例","level":"1.12.3","depth":2,"next":{"title":"音视频术语-文件格式-协议","level":"1.13","depth":1,"path":"chinese/视频相关/音视频基础.md","ref":"chinese/视频相关/音视频基础.md","articles":[{"title":"音视频基础","level":"1.13.1","depth":2,"path":"chinese/视频相关/音视频基础.md","ref":"chinese/视频相关/音视频基础.md","articles":[]},{"title":"RTSP","level":"1.13.2","depth":2,"path":"chinese/视频相关/RTSP.md","ref":"chinese/视频相关/RTSP.md","articles":[]},{"title":"RTP","level":"1.13.3","depth":2,"path":"chinese/视频相关/RTP.md","ref":"chinese/视频相关/RTP.md","articles":[]},{"title":"RTCP","level":"1.13.4","depth":2,"path":"chinese/视频相关/RTCP.md","ref":"chinese/视频相关/RTCP.md","articles":[]},{"title":"H264","level":"1.13.5","depth":2,"path":"chinese/视频相关/H264.md","ref":"chinese/视频相关/H264.md","articles":[]},{"title":"YUV","level":"1.13.6","depth":2,"path":"chinese/视频相关/YUV.md","ref":"chinese/视频相关/YUV.md","articles":[]},{"title":"SurfaceView","level":"1.13.7","depth":2,"path":"chinese/视频相关/SurfaceView.md","ref":"chinese/视频相关/SurfaceView.md","articles":[]},{"title":"RTMP","level":"1.13.8","depth":2,"path":"chinese/视频相关/RTMP.md","ref":"chinese/视频相关/RTMP.md","articles":[]},{"title":"AAC详解","level":"1.13.9","depth":2,"path":"chinese/视频相关/AAC详解.md","ref":"chinese/视频相关/AAC详解.md","articles":[]}]},"previous":{"title":"GLSL基础","level":"1.12.2","depth":2,"path":"chinese/openGLES/GLSL基础.md","ref":"chinese/openGLES/GLSL基础.md","articles":[]},"dir":"ltr"},"config":{"plugins":["-search","search-plus","todo","anchor-navigation-ex","copy-code-button","versions-select","fontsettings","sharing","tbfed-pagefooter","donate","local-video","splitter","edit-link","expandable-chapters","favicon","theme-comscore","local-video"],"styles":{"website":"styles/website.css"},"pluginsConfig":{"tbfed-pagefooter":{"copyright":"无版权 可以无限制使用！","modify_label":"该文件更新时间：","modify_format":"YYYY-MM-DD HH:mm:ss"},"todo":{},"splitter":{},"lunr":{"maxIndexSize":1000000,"ignoreSpecialCharacters":false},"versions-select":{"type":"branches"},"donate":{"alipay":"https://gitee.com/hnyer/filesOfGitbook/raw/master/files/201803011956_osChina_支付宝收款码.png","alipayText":"支付宝打赏","button":"打赏","title":"","wechat":"https://gitee.com/hnyer/filesOfGitbook/raw/master/files/201803011956_osChina_微信收款码.png","wechatText":"微信打赏"},"fontsettings":{"family":"sans","size":2,"theme":"sepia"},"highlight":{},"anchor-navigation-ex":{"associatedWithSummary":true,"float":{"floatIcon":"fa fa-navicon","level1Icon":"","level2Icon":"","level3Icon":"","showLevelIcon":false},"mode":"float","multipleH1":true,"pageTop":{"level1Icon":"","level2Icon":"","level3Icon":"","showLevelIcon":false},"printLog":false,"showGoTop":true,"showLevel":true},"favicon":{"shortcut":"assets/images/favicon.ico","bookmark":"assets/images/favicon.ico"},"theme-comscore":{},"local-video":{},"copy-code-button":{},"versions":{"options":[{"value":"https://www.aivin666.cn/java_android/","text":"v1.0"}]},"sharing":{"all":["facebook","google","twitter","weibo","instapaper"],"facebook":false,"google":true,"instapaper":false,"twitter":false,"vk":false,"weibo":true},"edit-link":{"label":"托管页面","base":"https://www.baidu.com/"},"theme-default":{"styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"},"showLevel":false},"expandable-chapters":{},"search-plus":{}},"theme":"default","author":"Aivin","pdf":{"pageNumbers":true,"fontSize":12,"fontFamily":"Arial","paperSize":"a4","chapterMark":"pagebreak","pageBreaksBefore":"/","margin":{"right":62,"left":62,"top":56,"bottom":56}},"structure":{"langs":"LANGS.md","readme":"README.md","glossary":"GLOSSARY.md","summary":"SUMMARY.md"},"variables":{},"title":"Aivin开发笔记","language":"zh-hans","gitbook":"*","description":"Aivin开发笔记"},"file":{"path":"chinese/openGLES/openglES示例.md","mtime":"2020-08-20T06:17:31.520Z","type":"markdown"},"gitbook":{"version":"3.2.3","time":"2020-08-20T09:02:41.305Z"},"basePath":"../..","book":{"language":""}});
        });
    </script>
</div>

        
    <script src="../../gitbook/gitbook.js"></script>
    <script src="../../gitbook/theme.js"></script>
    
        
        <script src="../../gitbook/gitbook-plugin-search-plus/jquery.mark.min.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-search-plus/search.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-copy-code-button/toggle.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-versions-select/plugin.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-fontsettings/fontsettings.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-sharing/buttons.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-donate/plugin.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-local-video/video.min.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-splitter/splitter.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-edit-link/plugin.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-expandable-chapters/expandable-chapters.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-lunr/lunr.min.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-lunr/search-lunr.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-theme-comscore/test.js"></script>
        
    

    </body>
</html>

